<?php

namespace App\Http\Controllers\Admin;

use App\Http\Query\CategoryQuery;
use app\Model\Base;
use app\Model\OrderModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Log;
use function MongoDB\BSON\toJSON;
use SplFileObject;

class JapanShowBayController extends Controller

{

    function show_bay(Request $request)
    {
        $getParam = $request->all();
        $map = [];

        if (!empty($getParam['supplier_id'])) {
            $map['sm.supplier_id'] = $getParam['supplier_id'];
        }
//        dump($getParam);
        if (!empty($getParam['category_id'])) {
            $map['cm.category_id'] = $getParam['category_id'];
        }
        $db = DB::table('suppiler_order as so')
            ->select(DB::raw('so.supplier_order_id,so.order_id,cm.category_name,gm.goods_code,so.goods_id,so.goods_name,so.color,so.size,so.num,so.create_time,so.total_price,1 AS warehouse_name,so.remark'))
            ->leftJoin('goods_master as gm', 'so.goods_id', '=', 'gm.goods_id')
            ->leftJoin('supplier_master as sm', 'sm.supplier_id', '=', 'so.supplier_id')
            ->leftJoin('category_master as cm', 'gm.category_id', '=', 'cm.category_id')
            ->where($map)
            ->orderBy('so.create_time', 'asc');

        if (!empty($getParam['star_date']) && !empty($getParam['end_date'])) {
            $list = $db->whereBetween('so.create_time', [$getParam['star_date'], $getParam['end_date']])->get();
        } else {
            $list = $db->get();
        }
        $mo = new \App\Model\OrderModel();
        return view('warehouse.show_bay', array(
            'list' => $list,
            'goods' => $mo::goods(),
            'supplier' => $mo::supplier_master(),
            'category' => $mo::category(),
            'param' => $getParam,
        )); // 返回视图

    }
}
